package com.igeek.d0605;

import java.util.Arrays;
import java.util.Comparator;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @Author: zhiyu
 * @Date:18:12
 * @DESC:
 */
public class CollectorsApi {
    public static void main(String[] args) {
        //1.将英文字符串的数组中的元素全部变为大写，以集合输出。将整数的数组中的元素全部加3，以集合输出。
        String[] arr = {"scas","dsadasda","asdasds","dfsdd"};
        Arrays.asList(arr).stream().map(String::toUpperCase).forEach(System.out::println);
        Integer[] arrInt = {1,23,3,34,5,56,776,76};
        Arrays.asList(arrInt).stream().map(i->i+3).forEach(System.out::println);
        //2.统计员工人数、平均工资、工资总额、最高工资、统计工资的所有信息。
        //        counting() 、averagingDouble()、maxBy()、summingInt()、summarizingDouble()
        Employee e1 = new Employee("张三", 18888.0,18,"男");
        Employee e2 = new Employee("李四", 10888.0,23,"男");
        Employee e3 = new Employee("王五", 7888.0,25,"女");
        Employee e4 = new Employee("赵六", 7888.0,24,"女");
        System.out.println("Stream.of(e1,e2,e3,e4).collect(Collectors.counting()) = " + Stream.of(e1, e2, e3, e4).collect(Collectors.counting()));
        System.out.println("Stream.of(e1, e2, e3, e4).collect(Collectors.averagingDouble(Employee::getSalary)) = " + Stream.of(e1, e2, e3, e4).collect(Collectors.averagingDouble(Employee::getSalary)));
        System.out.println("Stream.of(e1, e2, e3, e4).collect(Collectors.summarizingDouble(Employee::getSalary)) = " + Stream.of(e1, e2, e3, e4).collect(Collectors.summarizingDouble(Employee::getSalary)));
        System.out.println("Stream.of(e1, e2, e3, e4).collect(Collectors.maxBy(Comparator.comparingDouble(Employee::getSalary))) = " + Stream.of(e1, e2, e3, e4).collect(Collectors.maxBy(Comparator.comparingDouble(Employee::getSalary))));
        //3.将员工按薪资是否高于8000分为两部分；将员工按性别分组；将员工按性别和地区分组。
        //        partitioningBy()、groupingBy()
        System.out.println("Stream.of(e1, e2, e3, e4).collect(Collectors.groupingBy(Employee::getSex)) = " + Stream.of(e1, e2, e3, e4).collect(Collectors.groupingBy(Employee::getSex)));
        System.out.println("Stream.of(e1, e2, e3, e4).collect(Collectors.partitioningBy(employee -> employee.getSalary()>8000)) = " + Stream.of(e1, e2, e3, e4).collect(Collectors.partitioningBy(employee -> employee.getSalary() > 8000)));
        //4.将所有员工的名称用逗号拼接
        //        joining()
        System.out.println("Stream.of(e1, e2, e3, e4).map(Employee::getName).collect(Collectors.joining(\",\")) = " + Stream.of(e1, e2, e3, e4).map(Employee::getName).collect(Collectors.joining(",")));
    }
}
